/*
 * NestedLoopDetector.h: 2010-4-9
 * Use static analysis to detect nested loop
 * in the source program before run.
 * By: G-Crossbit Group, Zhang Yichao
 */

#ifndef NESTEDLOOPDETECTOR_H
#define NESTEDLOOPDETECTOR_H

#include "crossbit/common.h"
#include "crossbit/VBlock.h"
#include "crossbit/Interpreter.h"
#include <set>
#include <map>

namespace crossbit
{
	class NestedLoopDetector
	{
		public:
			NestedLoopDetector( Interpreter *i )
				: start(0), end(0), interp(i)
			{}
			NestedLoopDetector(XTMemAddr a, XTMemAddr b, Interpreter *i)
				: start(a), end(b), interp(i)
			{}

			virtual ~NestedLoopDetector() {}

			virtual void run() = 0;

			// Decode jmp instruction at "addr"
			// find a loop if it jumps backward
			virtual XTMemAddr decode(XTMemAddr addr) = 0;

			virtual XTInt32 isNestedLoop(XTMemAddr entry) = 0;

			virtual void printNestedLoops() = 0;

			virtual void setTextSectionRange( XTMemAddr s, XTMemAddr e )
			{
				start = s;
				end = e;
			}

		protected:
			XTMemAddr start;	// start addr of .text section
			XTMemAddr end;		// end addr of .text section
			Interpreter *interp;
	};
}

#endif
